/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.feiyue.basic.reader.data.store;

import com.feiyue.basic.reader.data.net.BaseHttp;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

public abstract class Store {
	public static final int TIME_OUT_CODE = 20;
	private BaseHttp http;
	private List<NameValuePair> params;
	private String[] paramsName;
	private String[] paramsValue;
	protected String url = "http://192.168.0.42:8088/ibooks";

	private void setParam(String paramString1, String paramString2) {
		this.params.add(new BasicNameValuePair(paramString1, paramString2));
	}

	public boolean delete() throws Exception {
		return update();
	}

	protected String load() throws Exception {
		this.params = new ArrayList();
		StringBuffer localStringBuffer = new StringBuffer();
		localStringBuffer.append("?");
		int i = 0;
		int j = this.paramsName.length;
		while (true) {
			if (i >= j) {
				localStringBuffer.deleteCharAt(-1 + localStringBuffer.length());
				this.http = new BaseHttp(this.url
						+ localStringBuffer.toString());
				return this.http.doPost();
			}
			localStringBuffer.append(this.paramsName[i]).append("=")
					.append(this.paramsValue[i]).append("&");
			++i;
		}
	}

	public long save() throws Exception {
		JSONObject localJSONObject = new JSONObject(load());
		if (localJSONObject.optLong("code") == 1L)
			return localJSONObject.optLong("response");
		return 0L;
	}

	public void setParamsName(String[] paramArrayOfString) {
		this.paramsName = paramArrayOfString;
	}

	public void setParamsValue(String[] paramArrayOfString) {
		this.paramsValue = paramArrayOfString;
	}

	public void setUrl(String paramString) {
		this.url = paramString;
	}

	public boolean update() throws Exception {
		return (new JSONObject(load()).optLong("code") == 1L);
	}
}